package cn.edu.ujs.coor.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 对返回信息进行封装
 *
 * @author 柳曾雄
 * @date 2018-07-16
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class JsonResponse<T> {

    private Boolean flag;

    private T data;

    private String code;

    private String message;

    /**
     * 成功
     * @param object
     * @return
     */
    public static JsonResponse success(Object object) {
        return JsonResponse
                .builder()
                .flag(true)
                .data(object)
                .code("er_000000")
                .build();
    }

    /**
     * 成功
     * @return
     */
    public static JsonResponse success() {
        return success("");
    }

    /**
     * 失败
     * @param message
     * @return
     */
    public static JsonResponse fail(String code, String message) {
        return JsonResponse
                .builder()
                .flag(false)
                .code(code)
                .message(message)
                .build();
    }
}
